<template>
	<view class="container bg-w">
		<view class="header uni-flex uni-row flex-between">
			<uni-nav-bar title="考核评分">
				<template slot='left'>
					<view class="flex width-100 ">
						<i class='iconfont iconfanhui' @click='goBack()'></i>
					</view>
				</template>
			</uni-nav-bar>
		</view>
		<view class="position-r-top">
			<view v-for="(item,index) in examineData" :key="index">
				<uni-card :title="item.subAssessmentName">
					<template slot='header'>
						<input type="number" v-model="item.score" style="text-align: right;" :placeholder="`请输入评分共(${item.fraction})`" @input="fractionChange(index,item.fraction)"/>
					</template>
				  {{ item.standard }}
					<!-- <template slot='footer'>
						<input type="text" v-model="item.remarks" placeholder="请输入备注..."/>
					</template> -->
				</uni-card>
			</view>
			
			<view>
				<button class="submit-btn" type="submit" @click="auditSubmitHandle">提交审核</button>
			</view>
		</view>
	</view>
</template>

<script>
	import { auditSubmit, examine } from '@/common/api/ConstructionAudit'
	export default {
		data() {
			return {
				assessmentId: '',
				params: {},
				examineData: []
			}
		},
		onLoad(option) {
			this.assessmentId = option.assessmentId;
			this.params = JSON.parse(decodeURIComponent(option.params));
			this.loadExamineData();
		},
		methods: {
			loadExamineData() {
				examine(this.assessmentId).then((res) => {
					if(res.code == 20000){
						let detailedProId = this.params.reportEquipmentVos[0].detailedProId;
						this.examineData = res.data;
						this.examineData.forEach((item)=> {
							this.$set(item, 'score', item.fraction);
							this.$set(item, 'detailedProId', detailedProId);
							this.$set(item, 'remarks', '');
						})
					}
				})
			},
			fractionChange(index, fraction) {
				let score = this.examineData[index].score;
				if(Number(score) > fraction) this.examineData[index].score = '';
			},
			auditSubmitHandle() {
				let flag = 0;
				this.examineData.forEach((item) => {
					if (item.score == '') flag++;
				})
				if (flag != 0) {
					uni.showToast({
						title: '请完善分数信息',
						icon: 'none'
					})
				}else{
					this.params.projectProcessScores = this.examineData;
					auditSubmit(this.params).then((res)=> {
						if (res.code == 20000) {
							uni.showToast({
								title: '提交成功',	
								icon: 'none'
							})
							setTimeout(() => {
								uni.navigateBack({
									delta: 1
								});
							}, 1000)
						}
					})
				}
				
			}
		}
	}
</script>

<style lang="less">
	.submit-btn {
		position: fixed;
		bottom: 0;
		left: 5%;
		width: 90%;
		margin: 20rpx auto;
		height: 80rpx;
		line-height: 80rpx;
		font-size: 28rpx;
		background-color: #09AAE9;
		color: #fff;
		border-radius: 50rpx;
	}
</style>
